package cn.snews.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import news.topic;
import toolDAO.Page;
import dao.TopicDAO;

public class TopUpServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6954012568560883168L;

	/**
	 * Constructor of the object.
	 */
	public TopUpServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		List<topic> list = TopicDAO.showAll();

		int pageNo = 1;
		try {
			pageNo = Integer.parseInt(request.getParameter("pageNo"));
		} catch (Exception e) {
		}// 忽略所有异常
		Page<topic> p = TopicDAO.find(pageNo);
		request.setAttribute("topic", list);
		request.setAttribute("p", p);
		request.getRequestDispatcher("/WEB-INF/jsp/uptopic.jsp").forward(
				request, response);
	}

	public void init() throws ServletException {
	}

}
